cmake_minimum_required(VERSION 3.10)

# 设置项目名称
project(S7_Midi_Tool)

set(CMAKE_BUILD_TYPE Debug)

# get_cmake_property(_variableNames VARIABLES)
# foreach(_variableName ${_variableNames})
#     message(STATUS "${_variableName}=${${_variableName}}")
# endforeach()

# 判断编译器
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
    message(">> using Clang")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
    message(">> using GCC")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
    message(">> using Intel C++")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
    message(">> using Visual Studio C++")
    # 编译窗口程序
    # set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS /NODEFAULTLIB:LIBCMT" ) 
    set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:LIBCMT" ) 
    # 库路径
    # set(LIBUSB_LIBRARYS_PATH D:/librarys/libusb/VS2022/MS64)
    # set(LIBUSB_INCLUDE_PATH D:/librarys/libusb)
    set(MSVC_LIBRARYS kernel32
    user32
    gdi32
    comdlg32
    winspool
    winmm
    shell32
    shlwapi
    comctl32
    ole32
    oleaut32
    uuid
    rpcrt4
    advapi32
    version
    ws2_32
    wininet
    oleacc
    uxtheme
    bthprops
    )
    # set(LINKOPTION "/NODEFAULTLIB:msvcrt.lib")
else()
    message(">> unknow compiler.")
endif()

# set(CMAKE_SUBSYSTEM_WINDOWS "WINDOWS")


# 设置编译类型为Release
# set(CMAKE_BUILD_TYPE ${buildType})

# 生成文件名称
set(OUT_FILE_NAME S7_Midi_Tool)


# 指定C++标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# 指定使用MSVC编译器
# set(CMAKE_CXX_COMPILER "cl")
if(MSVC)
    # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /Zi")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /source-charset:utf-8 /execution-charset:utf-8")
endif(MSVC)

if(CMAKE_BUILD_TYPE MATCHES "Debug")
    message(">>>> CMAKE_BUILD_TYPE is Debug")
    set(WX_LIB_SUFFIX ud)
else()
  # Release 模式
  message(">>>> CMAKE_BUILD_TYPE is Release")
  set(WX_LIB_SUFFIX u)
endif()

# 添加宏定义
add_definitions(-D_UNICODE)


# 指定源文件
set(SOURCE_FILES main.cpp
                 midifile/src/MidiFile.cpp
                 midifile/src/Binasc.cpp
                 midifile/src/MidiEvent.cpp
                 midifile/src/MidiEventList.cpp
                 midifile/src/MidiMessage.cpp
                 midifile/src/Options.cpp
)

# 添加多个头文件目录
include_directories(${CMAKE_SOURCE_DIR}/midifile/include
)

# 添加多个库文件目录
link_directories(${WXWIDGETS_LIBRARYS_PATH}
                 ${LIBUSB_LIBRARYS_PATH}/static
)

# 指定编译输出目录
# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/build_out)

# 添加可执行文件
add_executable(${OUT_FILE_NAME} ${SOURCE_FILES})

# 添加链接选项
target_link_options(${OUT_FILE_NAME} PRIVATE ${LINKOPTION})

# 添加多个库文件
target_link_libraries(${OUT_FILE_NAME} ${LIBRARYS_USE} ${MSVC_LIBRARYS})


# Release 模式
# target_link_libraries(${OUT_FILE_NAME} wxmsw32u_core wxbase32u)


# 在编译成功后，自动执行拷贝MyProject.exe文件到指定目录下
# add_custom_command(TARGET ${OUT_FILE_NAME} POST_BUILD
#                    COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${OUT_FILE_NAME}> ${CMAKE_SOURCE_DIR})

# 添加自定义命令，在编译后复制DLL文件
# add_custom_command(TARGET ${OUT_FILE_NAME} POST_BUILD
#                    COMMAND ${CMAKE_COMMAND} -E copy_directory
#                    ${CMAKE_SOURCE_DIR}/dll_dir $<TARGET_FILE_DIR:${OUT_FILE_NAME}>)
